package com.csmall.business.service.Impl;

import com.csmall.business.service.BusinessService;
import com.csmall.commons.pojo.order.dto.OrderAddDTO;
import com.csmall.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @Name: BusinessServiceImpl
 * @Author: 西风残叶
 * @Date: 2024/8/18 15:59
 * @Version: 1.0
 * @TODO: TODO
 */
@Service
@Slf4j
public class BusinessServiceImpl implements BusinessService {
    @DubboReference
    private OrderService dubboOrderService;
    /**
     * 触发提交订单业务
     * 该方法负责处理所有购买相关的逻辑
     */
    @GlobalTransactional
    @Override
    public void buy() {
        OrderAddDTO orderAddDTO = new OrderAddDTO();
        orderAddDTO.setCommodityCode("PC100");
        orderAddDTO.setCount(5);
        orderAddDTO.setMoney(500);
        orderAddDTO.setUserId("UU100");
        // 提交订单
        log.info("提交订单：{}", orderAddDTO);
        dubboOrderService.orderAdd(orderAddDTO);
        log.info("提交订单成功");
    }
}